class Solution:
    def reverseWords(self, s: str) -> str:
        words = ""
        start = 0
        while start < len(s) and s[start] == ' ':
            start = start + 1
        nowWord = ""
        for i in range(start, len(s)):
            if s[i] == ' ':
                if nowWord != '':
                    words = nowWord + " " + words
                    nowWord = ""
                else:
                    continue
            else:
                nowWord = nowWord + s[i]
        if nowWord:
            words = nowWord + " " + words
        return words[:-1]


if __name__ == '__main__':
    so = Solution()
    s = "   "
    r = so.reverseWords(s)
    print(r)
